package com.apps.apicontroller;

import com.apps.common.model.po.ApiResult;
import com.apps.helper.PageConextHelper;
import com.apps.member.service.IKupaMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 一些全局接口
 */
@Slf4j
@Api(description = "用户登录注册接口")
@RestController
@RequestMapping("/api/login")
public class MemberLoginAndRegApiController
{

    @Autowired
    private IKupaMemberService memberService;

    @ApiOperation(value = "手机号登录/注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "注册手机号", required = true,dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "validcode", value = "手机验证码", required = true,dataType = "string",paramType = "query")
    })
    @PostMapping("/mobileRegist")
    ApiResult<String> MobileRegist(@RequestParam(value = "mobile") String mobile,
                                   @RequestParam(value = "validcode") String validcode)
    {
        ApiResult<String> result = new ApiResult<>();
        memberService.mobileLogin(mobile,validcode);
        return result.success("注册成功");
    }

    @ApiOperation(value = "邮箱登录/注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "注册邮箱号", required = true,dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "validcode", value = "邮箱验证码", required = true,dataType = "string",paramType = "query")
    })
    @PostMapping("/emailRegist")
    ApiResult<String> EmailRegist(@RequestParam(value = "email") String email,
                                  @RequestParam(value = "validcode") String validcode)
    {
        ApiResult<String> result = new ApiResult<>();
        memberService.emailLogin(email,validcode);
        return result.success(PageConextHelper.getHistoryPage());
    }

}
